package com.rtzh.learnkotlin.ui

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.rtzh.learnkotlin.R
import com.rtzh.learnkotlin.adapter.FruitAdapter
import com.rtzh.learnkotlin.bean.Fruit
import kotlinx.android.synthetic.main.activity_recycler.*

/**
 * RecyclerView基础使用
 */
class RecyclerViewActivity : AppCompatActivity() {
    private val fruitList = ArrayList<Fruit>();
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_recycler)
        initViews()
    }

    private fun initViews() {
        initFruits();
        val layoutManager = LinearLayoutManager(this);
        recyclerview.layoutManager = layoutManager;
        layoutManager.orientation = LinearLayoutManager.VERTICAL
        val adapter = FruitAdapter(fruitList);
        recyclerview.adapter = adapter;
    }

    fun initFruits() {
        repeat(10) {
            fruitList.add(Fruit("苹果", R.drawable.ic_launcher_foreground))

        }
    }
}